class Solution:
	# @param {integer} num
	# @return {string}
	def intToRoman(self, num):
		base = [
			['I','V'],
			['X','L'],
			['C','D'],
			['M']
		]
		digs = [int(i) for i in list(str(num))]
		pos = len(digs) 
		ans = ""
		for d in digs:
			pos -= 1
			tmp = ""
			if d <= 3:
				tmp += base[pos][0] * d
			elif d == 4:
				tmp += base[pos][0] + base[pos][1]
			elif d < 9:
				tmp += base[pos][1] + base[pos][0] * (d-5)
			else:
				tmp += base[pos][0] + base[pos+1][0] 
			ans += tmp
		return ans

if __name__ == '__main__':
	so = Solution()
	print so.intToRoman(3999)